package com.lz.comm.image.progress

import java.util.*

object ProgressDispatcher : ProgressCallback {

    private val listeners = Collections.synchronizedMap(WeakHashMap<String, OnProgressListener>())

    fun addOnProgressListener(url: String, listener: OnProgressListener) {
        listeners[url] = listener
    }

    fun removeOnProgressListener(url: String) {
        listeners.remove(url)
    }

    override fun progress(url: String, bytesRead: Long, totalBytes: Long) {
        listeners[url]?.onProgress(bytesRead, totalBytes)
    }

}